<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Vue</title>
    <!-- 引入样式 -->
    <link rel="stylesheet" href="css/index.css">
    <link rel="stylesheet" href="css/customer.css">
    <link rel="stylesheet" type="text/css" href="css/styles.css">
    <!-- 引入组件库 -->
    <script src="js/jquery-1.11.1.min.js"></script>
    <script src="js/vue.v2.6.14.js%20.js"></script>
    <script src="js/index.js"></script>
    <script src="js/axios.v0.21.1.min.js"></script>
</head>
<body>
<div id="app">
    <div class="wrapper">
        <div class="container">
            <h1>博客后台管理系统</h1>
    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
        <el-form-item label="用户名" prop="uname">
            <el-input v-model="ruleForm.uname"></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="upass">
            <el-input v-model="ruleForm.upass"></el-input>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" @click="submitForm('ruleForm')">立即登录</el-button>
            <el-button @click="resetForm('ruleForm')">重置</el-button>
        </el-form-item>
    </el-form>
    </div>
        <ul class="bg-bubbles">
            <li></li>
            <li></li>
        </ul>
    </div>
</div>
</body>
<script>
    new Vue({
        el: '#app',
        data: {
            ruleForm: {
                uname: '',
                upass: ''
            },
            rules: {
                uname: [
                    {required: true, message: '请输入用户名', trigger: 'blur'},
                ],
                upass: [
                    {required: true, message: '请输入密码', trigger: 'blur'},
                ]
            }
        },
        methods:{
            submitForm(formName) {
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        axios.post(`/user/login/${this.ruleForm.uname}/${this.ruleForm.upass}`).then(response=>{
                            if (response.data){
                                this.$message.success("登录成功");
                                setTimeout(function () {
                                    location.href="index.html";
                                },1500);
                            }else {
                                this.$message.error("用户名或密码错误");
                                setTimeout(function () {
                                    location.href="login.html";
                                },1500);
                            }
                        })
                    } else {
                        this.$message.error('校验未通过!!');
                        return false;
                    }
                });
            },
            resetForm(formName) {
                this.$refs[formName].resetFields();
            }
        }
    });
</script>
</html>
